<%@ page import="java.util.List,java.io.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Edit Template Layout - iTextService</title>

</head>
<body>
<form action="SaveTemplate" method="post">
<table align="center" cellpadding="0" cellspacing="0" style="width:400px; border: 0px black solid;">
	<tr>
		<td style="text-align: left;width:150px;height:40px;">Template Name:
			<select name="templateName" id="templateName" style="width:190px;" onchange="showLayoutDetail();">
				<option value="">Please Select</option>
				<%
				String selectedTempateName = request.getParameter("templateName");
				String path = request.getSession().getServletContext().getRealPath("resources");
				File pathFile = new File(path);
				File[] files = pathFile.listFiles();
					for(File templateName : files){
						if(templateName.isDirectory()){
							String name = templateName.getName();
							if(name.equals(selectedTempateName)){
				%>
					<option value="<%=name%>" selected="selected"><%=name%></option>
				<%
							}else{
				%>
					<option value="<%=name%>"><%=name%></option>
				<%			    
							}
						}
				}
				%>
			</select>
		</td>
	</tr>
	<tr>
		<td colspan="2" style="text-align: left;width:150px;height:40px;">
			<textarea rows="30" cols="120" name="layoutXML" id="layoutXML"><%=request.getAttribute("layoutXML") %></textarea>
		</td>
	</tr>
	<tr>
		<td colspan="2" style="text-align: center;">
			<input align="center" type="submit" value="Submit">
		<input type="button" value="Cancel" onclick="window.location.href='index.jsp'">
		</td>
	</tr>
</table>
</form>

<script type="text/javascript">
function showLayoutDetail(){
	var templateName = document.getElementById("templateName").value;
	window.location.href='ShowTemplate?templateName=' + templateName;
}
</script>
</body>
</html>